package com.mycat.chat.two.util;

import com.google.gson.Gson;

import java.util.Map;

/**
 * JSON格式转换器
 *
 * @author roger.
 * @email 190642964@qq.com
 * @create 2017-02-24
 */
public class GsonUtil {

    /**
     * JSON字符串转换为Map
     * @param msg JSON字符串
     * @return  Map<String,Object>
     */
    public static Map<String,Object> toMap(String msg){
        Gson gson = new Gson();
        Map<String,Object> data =gson.fromJson(msg, Map.class);
        return data;
    }

    /**
     * JSON字符串转换为对象
     * @param msg JSON字符串
     * @param type 转换对象的Class
     * @param <T>
     * @return T
     */
    public static <T> T parseJson(String msg,Class<T> type){
        Gson gson = new Gson();
        return gson.fromJson(msg,type);
    }
}
